module.exports = {
  /**
   * 将数据转为树形结构
   * @param {数据} data
   * @param {数据id} id
   * @param {数据pid} pid
   * @returns
   */
  transTree(data, id, pid) {
    let result = []
    let map = {}
    data.forEach(item => {
      map[item[id]] = item
    })
    data.forEach(item => {
      let parent = map[item[pid]]
      if (parent) {
        ;(parent.children || (parent.children = [])).push(item)
      } else {
        result.push(item)
      }
    })
    return result
  }
}
